mui.init();

mui.plusReady(function () {
	document.getElementById("changepwd").addEventListener("tap",function(){
		changepwd();
	})
})
function changepwd() {
	var oldpw = document.getElementById('oldpw').value;
	var newpw = document.getElementById('newpw').value;
	var repw = document.getElementById('repw').value;
	var api_host = plus.storage.getItem('HOST_URL');
	
	if(oldpw == "") {
		mui.toast('请输入原密码', {
			duration: '1400',
			type: 'div'
		});
		return false;
	}
	if(repw=="") {
		mui.toast('请输入新密码', {
			duration: '1400',
			type: 'div'
		});
		return false;
	}
	if(repw=="") {
		mui.toast('请输入确认密码', {
			duration: '1400',
			type: 'div'
		});
		return false;
	}
	if(newpw != repw) {
		mui.toast('两次密码输入不正确', {
			duration: '1400',
			type: 'div'
		});
		return false;
	}
	
	mui.ajax({
		url: api_host + '/api/linxuan/user/changepw',
		dataType: 'json',
		data: {
			'oldpw': oldpw,
			'newpw': newpw
		},
		type: 'POST',
		async: true,
		headers:{'User-Token':plus.storage.getItem('UserToken')},
		timeout:3000,
		success: function(msg) {
			console.log(msg);
			if(msg.code=="1"){
				mui.toast(msg.msg, {duration: '1400',type: 'div'});
				//跳转到首页
				setTimeout(function () {
					mui.back();
				}, 1000)
			}else{
				mui.toast(msg.msg, {duration: '1400',type: 'div'});
			}
		},
		error: function(xhr, type, errorThrown) {
			console.log('系统错误！')
		}
	})
}